<?php
namespace Core\CoreContracts;
use Core;

require_once(CONTRACTS_DIR . 'statesuser.enum.php');
require_once(CONTRACTS_DIR . 'profilesuser.enum.php');
/*
* User definition
*/
class User 
{
	/**
    * @property integer $Id The user unique identifier
    */
	public $Id;
	
	/**
    * @property string $Firstname The user first name
    */
	public $Firstname;
	
	/**
    * @property string $Lastname The last name
    */
	public $Lastname;
	
	/**
    * @property string $Company The company name
    */
	public $Company;
	
	/**
    * @property string $Email The mail address 
    */
	public $Email;

	/**
    * @property string $PhoneNumber The phone number
    */
	public $PhoneNumber;
	
	/**
    * @property string $WebAddress The web address
    */
	public $WebAddress;
	
	/**
    * @property integer $State The user state ('Unknown','Online','Offline', 'Banned')
    */
	public $State;
	
	/**
    * @property integer $Profile The user profile ('User','Member','Administrator')
    */
	public $Profile;
	
	/**
    * @property string $Login The user login
    */
	public $Login;
	
	/**
    * @property string $Password The user password in sha1
    */
	public $Password;
	
	/**
	* @property blob $Avatar The user's avatar
	*/
	public $Avatar;
	
	/**
    * @property string $PictureMime The picture mime of the event
    */
	public $AvatarMime;
	
	/**
    * @property string $PictureExtension The picture extension of the event
    */
	public $AvatarExtension;
	
	/**
    * @property datetime $ModificationDate The user modification date
    */
	public $ModificationDate;
	
	/**
    * @property datetime $CreationDate The user creation date
    */
	public $CreationDate;
	
	/**
	* The default constructor
	*/
	public function __construct()  {  }
	
	/*
	* Build a new user object
	*
	* @param string $firstname The first name
	* @param string $lastname The last name
	* @param string $email The email
	* @param string $phonenumber The phone number
	* @param string $login The login
	* @param string $password The hashed password 
	* @param string $profile The profile (optionnal parameter, default is 'user')
	*/
	public static function Create($firstname, $lastname, $company, $email, $phonenumber, $webaddress, $login, $password, $profile = Core\CoreContracts\ProfileUser::User)
	{
		$user = new Core\CoreContracts\User();
		$user->Firstname = $firstname;
		$user->Lastname = $lastname;
		$user->Company = $company;
		$user->Email = $email;
		$user->PhoneNumber = $phonenumber;
		$user->WebAddress = $webaddress;
		$user->State = StateUser::NotValid;
		$user->Profile = $profile;
		$user->Login = $login;		
		$user->Password = $password;				
		$user->ModificationDate = date("Y-m-d H:i:s");
		$user->CreationDate = date("Y-m-d H:i:s");
		return $user ;
	}
	
	/**
	* Set user as online
	*/
	public function Online()
	{
		$this->ModificationDate = date("Y-m-d H:i:s");
		$this->State = StateUser::Online;
	}
	
	/**
	* Set user as offline
	*/
	public function Offline()
	{
		$this->ModificationDate = date("Y-m-d H:i:s");
		$this->State = StateUser::Offline;
	}
	
	/**
	* Convert an user to string
	*/
	public function  __toString()
	{
		return sprintf("%s %s", $this->Firstname, $this->Lastname);
	}
}
?> 